from django.conf import settings
from django.forms import ModelForm

from tinymce.widgets import TinyMCE

from capabilities import formfield_callbacks

from pr_j.models import Category, Project
    
class CategoryForm(ModelForm):
    formfield_callback = formfield_callbacks.html5
        
    def __init__(self, *args, **kwargs):
        super(CategoryForm, self).__init__(*args, **kwargs)
        self.fields['category'].widget.attrs['autofocus'] = 'autofocus'
        self.fields['summary'].widget = TinyMCE(attrs={'cols': 80, 'rows': 20})

    class Meta:
        model = Category
    
class ProjectForm(ModelForm):
    formfield_callback = formfield_callbacks.html5
    
    def __init__(self, *args, **kwargs):
        super(ProjectForm, self).__init__(*args, **kwargs)
        self.fields['title'].widget.attrs['autofocus'] = 'autofocus'
        self.fields['short_summary'].widget = TinyMCE(attrs={'cols': 80, 'rows': 10})
        self.fields['summary'].widget = TinyMCE(attrs={'cols': 80, 'rows': 20})
        self.fields['body'].widget = TinyMCE(attrs=settings.S_TE_TINYMCE_DEFAULT_ATTRS)
    class Meta:
        model = Project
